﻿
using Knlght.Domain;
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Knight.Models.Entity
{
    public class Administrators: TEntityBase
    {
        /// <summary>
        /// 主键Id GUID
        /// </summary>       
        public string Id { get; set; }
        /// <summary>
        /// 权限角色Id
        /// </summary>
        public int OwmRoleId { get; set; }
        /// <summary>
        /// 账号
        /// </summary>
        public string Username { get; set; }
        /// <summary>
        /// 昵称
        /// </summary>
        public string NickName { get; set; }
        /// <summary>
        /// 手机号码
        /// </summary>
        public string Phone { get; set; }
        /// <summary>
        /// 真实姓名
        /// </summary>
        public string RealName { get; set; }
        /// <summary>
        /// 邮箱
        /// </summary>
        public string Email { get; set; }
        /// <summary>
        /// 账户密码
        /// </summary>    
        public string Password { get; set; }
        /// <summary>
        /// 是否超级管理员
        /// </summary>
        public bool IsSuper { get; set; }
        /// <summary>
        /// 是否启用
        /// </summary>
        public bool IsEnabled { get; set; }
        public DateTime? BirthDay { get; set; }
        /// <summary>
        /// 添加时间
        /// </summary>      
        public DateTime AddTime { get; set; }
        /// <summary>
        /// 头像
        /// </summary>
        public string ImageUrl { get; set; }
        public string RoleName { get; set; }
    }

    public class AdministratorsMapping : EntityTypeConfiguration<Administrators>
    {
        public AdministratorsMapping()
        {
            // 设置表名
            this.ToTable("T" + nameof(Administrators));
            //设置主键
            HasKey(a => a.Id);
            //不自增
            this.Property(t => t.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
            //不更新
            this.Property(t => t.AddTime).HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed);
            //忽略列映射
            this.Ignore(p => p.RoleName);
            // 设置属性的类型和长度
            this.Property(a => a.Username).HasColumnType("NVarchar").HasMaxLength(200);
            this.Property(a => a.Email).HasColumnType("NVarchar").HasMaxLength(300);
        }
    }
}
